import os 
from modelscope import snapshot_download

def handler(event, context):
    repo_id = os.getenv('REPO_ID', '')
    cache_dir = os.getenv('CACHE_DIR', '')
    print(f"ready to download, check env params, REPO_ID: {repo_id}, CACHE_DIR: {cache_dir}")
    if repo_id == "":
        return "Fail, REPO_ID is empty"
    if cache_dir == "":
        return "Fail, CACHE_DIR is empty"
    
    model_repo_path = snapshot_download(repo_id=repo_id, cache_dir=cache_dir)
    print(f"download success, model is saved to: {model_repo_path}")
    return f"Success"


# debug use
if __name__ == '__main__':
    handler(None, None)